#!/usr/bin/python3
# -*- coding: UTF-8 -*-

import socket
import json
import time


BUFSIZE = 1460

host = '0.0.0.0'
port = 65510


try:
	log = open('mishi.log', 'a+')

	sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	sock.bind((host, port))

	while True:
	    data, (addr, port) = sock.recvfrom(BUFSIZE)
	    logstr = '%s addr %s port %d data %s\n' % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), addr, port, data)
	    # print(logstr)
	    log.write(logstr)
	    log.flush()

except Exception as e:
	raise e
finally:
	sock.close()
	log.close()
